<template>
	<el-dialog v-model="visible" title="明细 " :close-on-click-modal='false' :close-on-press-escape='false'
			   :fullscreen='true'>
		<el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
			<!-- <el-form-item>
                            <el-input v-model="dataForm.id" placeholder="id" clearable></el-input>
                          </el-form-item> -->

			<!--<el-form-item>-->
				<!--&lt;!&ndash; <el-input v-model="dataForm.status" placeholder="状态" clearable></el-input> &ndash;&gt;-->
				<!--<el-select size="small" v-model="dataForm.status " placeholder="请选择">-->
					<!--<el-option value="" label="&#45;&#45;"> </el-option>-->
					<!--<el-option v-for="item in checkStatus" :key="item.list" :label="item.listname"-->
							   <!--:value="reString(item.list)">-->
					<!--</el-option>-->
				<!--</el-select>-->
			<!--</el-form-item>-->

			<el-form-item>
				<el-input size="small" v-model="dataForm.sku" placeholder="物料编码" clearable></el-input>
			</el-form-item>
			<el-form-item>
				<el-input  size="small" v-model="dataForm.descr" placeholder="物料名称" clearable></el-input>
			</el-form-item>
			<!--<el-form-item>-->
				<!--<el-input size="small" v-model="dataForm.lot" placeholder="批号" clearable></el-input>-->
			<!--</el-form-item>-->
			<!--<el-form-item>-->
				<!--<el-input size="small" v-model="dataForm.location" placeholder="库位编码" clearable></el-input>-->
			<!--</el-form-item>-->
			<!--<el-form-item>-->
				<!--<el-input size="small" v-model="dataForm.tray" placeholder="箱" clearable></el-input>-->
			<!--</el-form-item>-->
			<el-form-item>
				<el-input size="small" v-model="dataForm.box" placeholder="格" clearable></el-input>
			</el-form-item>

			<el-form-item>
				<el-button size="small" @click="getDataList()">查询</el-button>
				<el-button size="small" @click="saveTransferFn()">检测完毕</el-button>
			</el-form-item>
			<!--  <el-form-item>
                            <el-button type="primary" @click="addOrUpdateHandle()">新增</el-button>
                          </el-form-item>

						  <el-form-item>
						    <el-button type="primary" @click="saveHandle()">保存</el-button>
						  </el-form-item>

                          <el-form-item>
                            <el-button type="danger" @click="deleteHandle()">删除</el-button>
                          </el-form-item> -->
			<!--<el-form-item>-->
				<!--<el-button size="small" type="info" @click="exportHandle()">导出</el-button>-->
			<!--</el-form-item>-->
		</el-form>
		<el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle"
				  @sort-change="dataListSortChangeHandle" style="width: 100%;" >
			<!-- <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column> -->
			<!--  <el-table-column prop="id" label="序号"  header-align="center"
                                           align="center"></el-table-column> -->
			<!--<el-table-column prop="checkkey" label="盘点号" header-align="center" align="center"></el-table-column>-->
			<!--<el-table-column prop="line" label="行号" header-align="center" align="center"></el-table-column>-->
			<!--  <el-table-column prop="status" label="状态"  header-align="center"
                                           align="center"></el-table-column> -->
			<!--<el-table-column prop="statusstr" label="状态" header-align="center" align="center"></el-table-column>-->
			<!--<el-table-column prop="sku" label="物料" header-align="center" align="center"></el-table-column>-->
			<el-table-column prop="descr" label="物料名称" header-align="center" align="center"></el-table-column>
			<el-table-column prop="tray" label="自箱" header-align="center" align="center"></el-table-column>
			<!--<el-table-column prop="lot" label="批号" header-align="center" align="center"></el-table-column>-->
			<!--<el-table-column prop="location" label="库位编码" header-align="center" align="center"></el-table-column>-->
			<el-table-column prop="totray" label="至箱" header-align="center" align="center">
				<template #default="scope">
					<el-input size="small"  placeholder="至箱" clearable v-model="scope.row.totray"></el-input>
				</template>
			</el-table-column>
			<el-table-column prop="tobox" label="格" header-align="center" align="center">
				<template #default="scope">
					<el-input size="small"  placeholder="格" clearable v-model="scope.row.tobox"></el-input>
				</template>
			</el-table-column>
			<el-table-column prop="toqty" label="数量" header-align="center" align="center">
				<template #default="scope">
					<el-input size="small"  placeholder="数量" clearable v-model="scope.row.toqty"></el-input>
				</template>
			</el-table-column>
			<el-table-column prop="factorycdoe" label="计量编码/工装号" header-align="center" align="center">
				<template #default="scope">
					<el-input size="small"  placeholder="计量编码/工装号" clearable v-model="scope.row.factorycdoe"></el-input>
				</template>
			</el-table-column>
			<!--<el-table-column prop="firstqty" label="初盘数量" header-align="center" align="center">-->
			<!--</el-table-column>-->
			<!--<el-table-column prop="secondqty" label="复盘数量" header-align="center" align="center">-->

			<!--</el-table-column>-->

			<!--<el-table-column prop="lot1" label="生产日期" header-align="center" align="center"></el-table-column>-->
			<el-table-column prop="lot2" label="有效日期" header-align="center" align="center">
				<template #default="scope">
					<el-date-picker size="small" v-model="scope.row.lot2" type="datetime" placeholder="选择时间"  value-format="YYYY-MM-DD HH:mm:ss" >
					</el-date-picker>
				</template>
			</el-table-column>
			<!--<el-table-column label='操作' fixed="right" header-align="center" align="center" width="80">-->
				<!--<template #default="scope">-->
					<!--&lt;!&ndash; <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button> &ndash;&gt;-->
					<!--<el-button type="text" size="small" v-if="!scope.row.lot  && hasPermission('lswms:check:delete') " @click="deleteHandle(scope.row.id)"  >删除-->
					<!--</el-button>-->
				<!--</template>-->
			<!--</el-table-column>-->
		</el-table>
		<el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
					   layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
					   @current-change="pageCurrentChangeHandle">
		</el-pagination>
		<!-- 弹窗, 新增 / 修改 -->
		<!--<checkdetailAddOrUpdate v-if="addOrUpdateVisible" ref="addOrUpdate" @refresh-data-list="getDataList">-->
		<!--</checkdetailAddOrUpdate>-->
	</el-dialog>
</template>

<script>
    import DataList from "@/utils/DataList";
    import {
        ref,
        reactive,
        onMounted,
        nextTick
    } from 'vue';
    import checkdetailAddOrUpdate from "@/components/lswms/check/CheckdetailAddOrUpdate";
    import {
        putCheckdetailEditUpdate
    } from '@/network/lswms/check/Checkdetail.js';
    import {
        getCodeListByCode
    } from "@/network/lswms/base/Codelist.js"
    import {
        ElMessage,
        ElMessageBox
    } from 'element-plus'
    import {
        getInventoryListByData,
        cargoDatail
    } from '@/network/lswms/stock/Inventory'


    //import {hasPermission} from "@/utils/hasPermission"
    export default {
        name: "checkdetail",


        components: {
            checkdetailAddOrUpdate,
        },

        setup() {
            const {
                dataForm,
                mixinViewModuleOptions,
                getDataList,
                dataList,
                total,
                page,
                limit,
                dataListLoading,
                dataListSelectionChangeHandle,
                dataListSortChangeHandle,
                pageSizeChangeHandle,
                pageCurrentChangeHandle,
                addOrUpdateHandle,
                deleteHandle,
                exportHandle,
                addOrUpdateVisible,
                dataListSelections,
                addOrUpdate
            } = DataList();

            onMounted(() => {
                mixinViewModuleOptions.value.getDataListIsPage = true;
                mixinViewModuleOptions.value.getDataListURL = '/lswms/inventory/cargodetail';
                mixinViewModuleOptions.value.deleteURL = '/lswms/inventory';
                mixinViewModuleOptions.value.exportURL = '/lswms/inventory/export';
                mixinViewModuleOptions.value.deleteIsBatchKey = 'id';
                mixinViewModuleOptions.value.deleteIsBatch = true

                dataForm.value = {
                    tray : dataForm.value.tray?dataForm.value.tray:''
                }
                if (mixinViewModuleOptions.value.activatedIsNeed) {
                    //getDataList();
                }
            })

			//检测完毕(箱转移功能)
            const saveTransferFn = () => {
                if (dataForm.value.tray.trim() == '' || dataForm.value.tray == null || dataForm.value.tray.trim()
                    .length == 0) {
                    return ElMessage.error("请录入箱号");
                }
                ElMessageBox.confirm('确定要转移箱吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(function() {
                    let data = dataList.value;
                    cargoDatail(data).then((res) => {
                        if (res.code != 0) {
                            return ElMessage.error(res.msg);
                        }
                        ElMessage({
                            message: '操作成功',
                            type: 'success',
                            duration: 500,
                            onClose: function() {
                                getDataList();
                            }
                        });

                    })
                }).catch(function() {})

            }

            const visible = ref(false);
            const init = () => {
                visible.value = true;
                checkStatusFn();
                nextTick(function() {
                    //  dataFormRef.value.resetFields();
                    // roleIdListDefault.value = [];
                    if (dataForm.value.tray) {
                        // dataForm.value.tray = dataForm.value.tray;
                        getDataList()
                    }

                })
            }

            const saveHandle = () => {

                putCheckdetailEditUpdate(dataList.value).then((res) => {
                    if (res.code !== 0) {
                        return ElMessage.error(res.data.msg);
                    }
                    ElMessage({
                        message: '操作成功',
                        type: 'success',
                        duration: 500,
                        onClose: function() {
                            getDataList();
                        }
                    });
                }).catch(function() {});
            }

            const checkStatus = ref("");

            const checkStatusFn = () => {

                getCodeListByCode('CheckStatus').then((res) => {
                    if (res.code !== 0) {
                        return ElMessage.error(res.msg);
                    }
                    checkStatus.value = res.data;
                }).catch((err) => {});
            }

            return {
                dataForm,
                mixinViewModuleOptions,
                getDataList,
                dataList,
                total,
                page,
                limit,
                dataListLoading,
                dataListSelectionChangeHandle,
                dataListSortChangeHandle,
                pageSizeChangeHandle,
                pageCurrentChangeHandle,
                addOrUpdateHandle,
                deleteHandle,
                exportHandle,
                addOrUpdateVisible,
                dataListSelections,
                addOrUpdate,
                init,
                visible,
                saveHandle,
                checkStatus,
                saveTransferFn
            }
        },
        methods: {
            //hasPermission

            reString: function(val) {
                let n = Number(val)
                if (!isNaN(n)) {
                    return n
                } else {
                    return val
                }
            }
        }
    }
</script>

<style scoped  lang="scss" >

</style>
